#include "mychart.h"

MyChart::MyChart(QWidget *parent) : QChartView(parent)
{
    mChart = new QChart();
    mChart->setTitle("Line chart");
    this->setChart(mChart);
}

void MyChart::setChartTitle(QString title)     //设置坐标标题
{
    mChart->setTitle(title);
}
void MyChart::addSeres(QLineSeries series, QString seriesName)      //添加一条曲线，使用对象的方式
{
    QLineSeries *seriesBuff = new QLineSeries(&series);
    seriesBuff->setName(seriesName);
    mChart->addSeries(seriesBuff);
    mChart->createDefaultAxes();
}

void MyChart::addSeres(QList<QPointF> dotList,QString seriesName)   //添加一条曲线，适用点的方式
{
    QLineSeries *series = new QLineSeries(mChart);
    series->setName(seriesName);
    series->append(dotList);
    mChart->addSeries(series);
    mChart->createDefaultAxes();
}

void MyChart::clearSeries() //清空所有曲线
{
    mChart->removeAllSeries();
}
void MyChart::removeSeries(QLineSeries *series)
{
    mChart->removeSeries(series);
}

QList<QAbstractSeries *> MyChart::getSeries()   //获取所有折线
{
    return mChart->series();
}
